<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="com.mes.entity.tdd.Staff" %>
<%@include file="/pages/common.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>待审批</title>
<script type="text/javascript">
$(function () {

    //1.初始化Table
    var oTable = new TableInit();
    oTable.Init();

    //2.初始化Button的点击事件
    var oButtonInit = new ButtonInit();
    oButtonInit.Init();
    toastr.options.positionClass = 'toast-top-center';
    
    $('#exampleModal').on('hide.bs.modal',function(){
    	$("#fm")[0].reset();
    	$('#fm').data('bootstrapValidator').resetForm(true);
    });
});


var TableInit = function () {
    var oTableInit = new Object();
    //初始化Table
    oTableInit.Init = function () {
        $('#tb_departments').bootstrapTable({
            url: '${pageContext.request.contextPath }/approveDetail/list.do',         //请求后台的URL（*）
            //showExport: true, //是否显示导出
            exportDataType: "basic", //basic', 'all', 'selected'.
            method: 'get',                      //请求方式（*）
            toolbar: '#toolbar',                //工具按钮用哪个容器
            striped: true,                      //是否显示行间隔色
            cache: false,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
            pagination: true,                   //是否显示分页（*）
            sortable: false,                     //是否启用排序
            sortOrder: "asc",                   //排序方式
            queryParams: oTableInit.queryParams,//传递参数（*）
            sidePagination: "server",           //分页方式：client客户端分页，server服务端分页（*）
            pageNumber:1,                       //初始化加载第一页，默认第一页
            pageSize: 10,                       //每页的记录行数（*）
            pageList: [10, 20, 30],        //可供选择的每页的行数（*）
            //search: true,                       //是否显示表格搜索，此搜索是客户端搜索，不会进服务端，所以，个人感觉意义不大
            strictSearch: true,
            //showColumns: true,                  //是否显示所有的列
            //showRefresh: true,                  //是否显示刷新按钮
            minimumCountColumns: 2,             //最少允许的列数
            clickToSelect: true,                //是否启用点击选中行
            height: 500,                        //行高，如果没有设置height属性，表格自动根据记录条数觉得表格高度
            uniqueId: "id",                     //每一行的唯一标识，一般为主键列
            //showToggle:true,                    //是否显示详细视图和列表视图的切换按钮
            //cardView: false,                    //是否显示详细视图
            detailView: false,                   //是否显示父子表
            columns: [{
                checkbox: true
            }, {
                field: 'id',
                title: 'id',
                visible: false
            }, {
                field: 'approve.type',
                title: '审批类别'
            }, {
                field: 'approve.number',
                title: '单据号'
            }, {
                field: 'approve.staff.staffname',
                title: '提交人'
            }, {
                field: 'approve.datetimes',
                title: '提交时间'
            }, {
                field: 'state',
                title: '审批状态',
                formatter:function(value,row,index){
            	    var result = "";
	                if(value==-1){
                        result =  "未审批";
	                }else if(value==0){
                        result =  "待审批";
	                }else if(value == 1) {
                        result =  "审核通过";
	                }else if (value == 2) {
	                    result = "审核驳回";
                    }
                    return result;
  	     		},
            }, {
                field: 'idea',
                title: '审批意见'
            }, {
                field: 'datetimes',
                title: '审批时间'
            }, {
                field: 'grade',
                title: '审批级别顺序'
            } ]
        });
    };

    //得到查询的参数
    oTableInit.queryParams = function (params) {
        var temp = {   //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
        	pageSize: params.limit,   //页面大小
            page: params.offset/params.limit+1,  //页码
            pid: $("#wsidTJ").val(),
            state: $("#wstareTJ").val(),
            'approve.type': $("#wtypeTJ").val()
        };
        return temp;
    };
    return oTableInit;
};


var ButtonInit = function () {
    var oInit = new Object();
    var postdata = {};

    oInit.Init = function () {
        //初始化页面上面的按钮事件
    };

    return oInit;
};

function shenPi() {
	var row=$.map($("#tb_departments").bootstrapTable('getSelections'),function(row){
		return row ;
	});
	/* if (row.length == 0) {
		toastr.warning('请至少选择一条数据!');
	}else{ */
		$("#bt").html("审批");
		$("#id").val(row.id);
		$("#idea").val("");
		$('#exampleModal').modal(open);
	//}
}
function updateWstare() {
	var bootstrapValidator = $("#fm").data('bootstrapValidator');  
    //开启验证
    bootstrapValidator.validate();  
    if (bootstrapValidator.isValid()){
		var url = "${pageContext.request.contextPath }/approveDetail/update.do";
		var title="审批";
	    $.post(url, $("#fm").serialize(), function(data) {
			if (data > 0) {
				toastr.success(title+'成功');
				setTimeout(function(){  //使用  setTimeout（）方法设定定时2000毫秒
					$('#exampleModal').modal('hide');
					$('#tb_departments').bootstrapTable('refresh');  
					refresh()
				},1000);
			} else {
				toastr.error(title+'失败，库位名称不能重复');
			}
		});
    }else{
	    return;  
    } 
}
function refresh(){
	setTimeout(function(){  //使用  setTimeout（）方法设定定时2000毫秒
		var row=$('#tb_departments').bootstrapTable('getData');
		if(row.length == 0){
			window.location.reload();
		}
	},1000);
}
function seach() {
	$('#tb_departments').bootstrapTable('refresh'); 
}
</script>
</head>
<body>
	<div class="panel-body" style="padding-bottom:0px;">
        <div class="panel panel-default">
            <div class="panel-heading">查询条件</div>
            <div class="panel-body">
                <form id="formSearch" class="form-horizontal">
                    <div class="form-group" style="margin-top:15px">
                        <label class="control-label col-sm-1" for="wtypeTJ">审批类别</label>
                        <div class="col-sm-3">
                        	<% Staff staff = (Staff)session.getAttribute("staff");%>
                        	<input type="hidden" id="wsidTJ" value="<%= staff.getStaffid()%>">
                        	<input type="hidden" id="wstareTJ" value="1,2">
                        	<input type="text" class="form-control" id="wtypeTJ">
                        </div>
                        <div class="col-sm-4" style="text-align:left;">
                            <button type="button" style="margin-left:50px" id="btn_query" class="btn btn-primary" onclick="seach()">查询</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>       

        <!-- <div id="toolbar" class="btn-group">
            <button id="btn_delete" type="button" class="btn btn-default" onclick="shenPi()">
                <span class="glyphicon glyphicon-folder-open" aria-hidden="true"></span> 标记为已读
            </button>
        </div> -->
        <table id="tb_departments"></table>
    </div>
    <div class="modal fade bs-example-modal-lg" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel">
   		<div class="modal-dialog" role="document">
    		<div class="modal-content">
      			<div class="modal-header">
        			<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        			<h4 class="modal-title" id="exampleModalLabel">
        				<span id="bt" style="font-size:13px"></span>
        			</h4>
      			</div>
      			<div class="modal-body">
	        		<form id="fm" class="form-horizontal"  style="margin-right: 5%;">
	          			<div class="form-group">
	           				 <label class="col-sm-2 control-label">意见:</label>
	            			 <div class="col-sm-10"> 
		            			 <input type="text" class="form-control" id="idea" name="idea" autocomplete="off">
		            			 <input type="hidden" id="id" name="id" >
		            			 <span class="xing"></span>
	          				</div>
	          			</div>
	          			
			      		<div class="modal-footer">
			      			<div class="col-sm-5 col-sm-offset-8">  
						        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
			      				<button type="button"  name="submit"  class="btn btn-primary" onclick="updateWstare()">保存</button>
			      			</div>
			      		</div>
	        		</form>
	      		</div>
    		</div>
  		</div>
	</div>
	<script type="text/javascript">
	$(function() {
		var layerTips = parent.layer === undefined ? layui.layer : parent.layer
		$("#fm").bootstrapValidator({
			feedbackIcons : {
				valid : 'glyphicon glyphicon-ok',
				invalid : 'glyphicon glyphicon-remove',
				validating : 'glyphicon glyphicon-refresh'
			},
			fields : {
				idea : {
					validators : {
						notEmpty : {
							message : '审批意见不能为空'
						},
					}
				},
			},
		});
	});
	</script>
</body>
</html>